from django.shortcuts import get_object_or_404
from django.forms import ModelForm, Textarea

from brispone.util import get_objects_page_context
from brispone.util.decorators import render_to
from brispone.models import Store, CATEGORY_CHOICES

class StoreForm(ModelForm):
    class Meta:
        model = Store
        fields = ('name', 'category')
        
@render_to('brispone/store/list.html')
def list(request):
    if request.method == 'POST':
        form = StoreForm(request.POST)
        print form
        name = form.cleaned_data['name']
        stores = Store.objects.filter(name=name)
    else:
        form = StoreForm()
        stores = Store.objects.all()[:5]
    return {
            'stores': stores,
            'form': form,
            }
 

@render_to('m/store/list.html')
def mlist(request):
#    if request.method == 'POST':
#        form = StoreForm(request.POST)
#        print form
#        name = form.cleaned_data['name']
#        stores = Store.objects.filter(name=name)
#    else:
#        form = StoreForm()
    return get_objects_page_context(Store.objects.all(), request.GET,)
            #search_form=AnalysisResultSearchForm(request.GET or None))

@render_to('brispone/store/detail.html')
def detail(request, store_id):
    store = get_object_or_404(Store, pk=store_id)
    return {'store':store}

@render_to('m/store/detail.html')
def mdetail(request, store_id):
    store = get_object_or_404(Store, pk=store_id)
    return {'store':store}